<script setup lang="ts">
// 逻辑
const store = useUserStore()
import { getUserInfoApI } from '@/apis/user'
import router from '@/router'
import { useUserStore } from '@/stores/user'
import type { userInfo } from '@/types/login'
import { HomeFilled, Document, DocumentRemove } from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { onMounted, ref } from 'vue'
const onLyout = () => {
  ElMessageBox.confirm('您确定要退出登录吗?', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning',
  })
    .then(() => {
      store.clearToken()
      router.push('/login')
      ElMessage.success('退出成功')
    })
    .catch(() => {})
}
const userInfo = ref<userInfo>()
onMounted(() => {
  getUserInfoApI().then((res) => {
    // console.log(res)
    userInfo.value = res.data
  })
})
</script>

<template>
  <el-container>
    <el-aside>
      <img src="../assets/images/logo.png" alt="" width="180" class="logo" />
      <el-menu
        background-color="#023"
        text-color="#fff"
        active-text-color="#ffd04b"
        style="border: none"
        router
      >
        <el-menu-item index="/">
          <el-icon><HomeFilled /></el-icon>概览页面</el-menu-item
        >
        <el-menu-item index="/article"
          ><el-icon><Document /></el-icon>文章管理</el-menu-item
        >
        <el-menu-item index="/publish"
          ><el-icon><DocumentRemove /></el-icon>发布文章</el-menu-item
        >
      </el-menu>
    </el-aside>
    <el-container>
      <el-header>
        <div>{{ userInfo?.mobile }}</div>
        <el-link :underline="false" @click="onLyout">退出</el-link>
      </el-header>
      <el-main>
        <!-- 路由出口 -->
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<style scoped>
/* 样式 */
.el-aside {
  width: 230px;
  height: 100vh;
  background-color: #023;
  text-align: center;
}
.logo {
  margin-top: 10px;
}
.el-header {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  border: 1px solid #ccc;
  gap: 10px;
}
</style>
